package com.darren.euc.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonFormat;

import net.sf.json.JSONArray;

@Entity
@Table(name = "euc_contract_product")
public class ContractProduct implements Serializable {

	private static final long serialVersionUID = 8419897234136199253L;

	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	/**
	 * 关联房间ID
	 */
	@Column(name = "room_id")
	private Integer roomId;

	@ManyToOne  
    @JoinColumn(name = "contract_id")  
	private Contract contract;
	

	@Column(name = "room_name", nullable = true, columnDefinition = "varchar", length = 255)
	private String roomName;

	@ManyToOne(targetEntity = RoomType.class, fetch = FetchType.EAGER)
	@JoinColumn(name = "room_type_id", referencedColumnName = "id")
	private RoomType roomType;

	@Column(name = "province_id")
	private String provinceId;

	@Column(name = "city_id")
	private String cityId;

	@Column(name = "space_id")
	private Integer spaceId;

	@Column(name = "room_price", nullable = true)
	private Double roomPrice;

	@Column(name = "seat_count", nullable = true)
	private Integer seatCount;
	
	/*
	 * 租赁开始时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	@Column(name = "rent_start", nullable = true, columnDefinition = "datetime")
	private Date rentStart;
	
	/*
	 * 租赁结束时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	@Column(name = "rent_end", nullable = true, columnDefinition = "datetime")
	private Date rentEnd;
	
	@Transient//是否快到期
	private boolean willOver = false;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@Column(name = "create_time", nullable = true, columnDefinition = "datetime")
	private Date createTime;

	@Column(name = "create_user_id")
	private Integer createUserId;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@Column(name = "last_modify_time", nullable = true, columnDefinition = "datetime")
	private Date lastModifyTime;

	@Column(name = "last_modify_user_id")
	private Integer lastModifyUserId;

	@Column(name = "enable", nullable = false, columnDefinition = "int default 1")
	private boolean enable = true;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getRoomId() {
		return roomId;
	}

	public void setRoomId(Integer roomId) {
		this.roomId = roomId;
	}

	public Contract getContract() {
		return null;//contract;
	}

	public void setContract(Contract contract) {
		this.contract = contract;
	}

	public String getRoomName() {
		return roomName;
	}

	public void setRoomName(String roomName) {
		this.roomName = roomName;
	}

	public RoomType getRoomType() {
		return roomType;
	}

	public void setRoomType(RoomType roomType) {
		this.roomType = roomType;
	}

	public String getProvinceId() {
		return provinceId;
	}

	public void setProvinceId(String provinceId) {
		this.provinceId = provinceId;
	}

	public String getCityId() {
		return cityId;
	}

	public void setCityId(String cityId) {
		this.cityId = cityId;
	}

	public Integer getSpaceId() {
		return spaceId;
	}

	public void setSpaceId(Integer spaceId) {
		this.spaceId = spaceId;
	}

	public Double getRoomPrice() {
		return roomPrice == null?0D:roomPrice;
	}

	public void setRoomPrice(Double roomPrice) {
		this.roomPrice = roomPrice;
	}

	public Integer getSeatCount() {
		return seatCount;
	}

	public void setSeatCount(Integer seatCount) {
		this.seatCount = seatCount;
	}
	
	public Date getRentStart() {
		return rentStart;
	}

	public void setRentStart(Date rentStart) {
		this.rentStart = rentStart;
	}

	public Date getRentEnd() {
		return rentEnd;
	}

	public void setRentEnd(Date rentEnd) {
		this.rentEnd = rentEnd;
	}

	public boolean isWillOver() {
		if(rentEnd != null){
			Date now = new Date();
			long days=(rentEnd.getTime()-now.getTime())/(1000*3600*24);
			if(days > 0 && days < 30){
				willOver = true;
			}
		}
		return willOver;
	}

	public void setWillOver(boolean willOver) {
		this.willOver = willOver;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Integer getCreateUserId() {
		return createUserId;
	}

	public void setCreateUserId(Integer createUserId) {
		this.createUserId = createUserId;
	}

	public Date getLastModifyTime() {
		return lastModifyTime;
	}

	public void setLastModifyTime(Date lastModifyTime) {
		this.lastModifyTime = lastModifyTime;
	}

	public Integer getLastModifyUserId() {
		return lastModifyUserId;
	}

	public void setLastModifyUserId(Integer lastModifyUserId) {
		this.lastModifyUserId = lastModifyUserId;
	}

	public boolean isEnable() {
		return enable;
	}

	public void setEnable(boolean enable) {
		this.enable = enable;
	}
}
